//
//  BTTrainingVC.m
//  BaxTer
//
//  Created by wsj2015 on 16/10/31.
//  Copyright © 2016年 陈武琦. All rights reserved.
//

#import "BTTrainingVC.h"
#import "BTTrainingCampVC.h"
#import "BTTrainingCell.h"
#import "BTSuperCollectView.h"
#import "BTTraniningModel.h"
#import "BerizeHeader.h"
#import "NSString+Utilities.h"
@interface BTTrainingVC ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (weak, nonatomic) IBOutlet BTSuperCollectView *collectionView;
@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *flowLayout;
@property (weak, nonatomic) IBOutlet UILabel *titleL;
@property (weak, nonatomic) IBOutlet BerizeHeader *brezerHeader;

@end

@implementation BTTrainingVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.collectionView registerNib:[UINib nibWithNibName:@"BTTrainingCell" bundle:nil] forCellWithReuseIdentifier:@"BTTrainingCell"];
    weakSelf_define;
    [self.brezerHeader showAnimtionWithColor:kMainColor];
    self.titleL.text = @"训练营";
    [self.collectionView wsj_HeaderRefreshBlock:^{
        [weakSelf getTrainingData];
        
    }];
    [self.collectionView.header beginRefreshing];
    
   
}
-  (void)configUI{
   
 
}
- (IBAction)pageBack:(id)sender {
    
    [self.navigationController popViewControllerAnimated:YES];
}



#pragma -mark 请求训练营数据
- (void)getTrainingData{
   
    weakSelf_define;
    self.collectionView.loading = YES;
    [[BTNetworkManager sharedMg] POST:kTrainingList parameters:nil success:^(NSDictionary * responseObject) {
        if (responseObject_success) {
            [weakSelf.collectionView.header endRefreshing];
            weakSelf.collectionView.loading = NO;
            [weakSelf.dataArray removeAllObjects];
            [weakSelf.dataArray addObjectsFromArray:[BTTraniningModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"]]];
            [weakSelf.collectionView reloadData];
        }
      
    } failure:^(NSString *err) {
         weakSelf.collectionView.loading = NO;
    }];
    
   
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
//    return self.dataArray.count;
    return self.dataArray.count;
}



- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    BTTrainingCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"BTTrainingCell" forIndexPath:indexPath];
    
    cell.model = self.dataArray[indexPath.row];
    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{

    BTTraniningModel *model = self.dataArray[indexPath.row];

    [self.navigationController popViewControllerAnimated:YES];
    self.selectBlock([model.id integerValue]);

}
@end
